package com.ytf.test.eighth;

class Actor{
    void act(){}
}
class HappyActor extends Actor{
    @Override
    void act() {
        System.out.println("HappyActor");
    }
}
class SadActor extends Actor{
    @Override
    void act() {
        System.out.println("SadActor");
    }
}
class Stage{
    private Actor actor = new HappyActor();
    void change(){
        actor = new SadActor();
    }
    void performPlay(){
        actor.act();
    }
}
/**
 * @author: YTF
 * @date: 2025/1/25 10:11
 * @version: 1.0
 * @description:
 */
public class Transmogrify {

    public static void main(String[] args) {
        Stage stage = new Stage();
        stage.performPlay();
        stage.change();
        stage.performPlay();
        /**
         * Output:
         * HappyActor
         * SadActor
         *
         * 总结：
         * 继承在编译时就知道确切的类型
         * 组合更加灵活，可以动态选择类型
         */
    }
}
